#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
           'setup.py',
           #'MANIFEST.in',
           'run_tests.sh',
           'requirements.txt',
           'test-requirements.txt',
           '.testr.conf',
           '.coveragerc',
          ]


setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/config/contrail_issu/" + file))

local_sources = [
           '__init__.py',
           'issu_contrail_common.py',
           'issu_contrail_config.py',
           'issu_contrail_post_sync.py',
           'issu_contrail_pre_sync.py',
           'issu_contrail_run_sync.py',
           'issu_contrail_zk_sync.py',
           'test',
          ]

local_sources_rules = []
for file in local_sources:
    local_sources_rules.append(
        env.Install("contrail_issu", "#controller/src/config/contrail_issu/contrail_issu/" + file))

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_gen = env.Command('dist/contrail_issu-0.1dev.tar.gz', 'setup.py',
                        cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, 'setup.py',
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Depends(install_cmd, sdist_depends)
    env.Alias('install', install_cmd)

# XXX Until we extend SetupPyTestSuite() to define tests as :flaky-test instead of :test,
#     this hack provents us from running this set of tests
if False:
    test_target = env.SetupPyTestSuite(sdist_gen,
                                       '/config/api-server/dist/contrail-api-server-0.1dev.tar.gz',
                                       '/config/schema-transformer/dist/schema_transformer-0.1dev.tar.gz')
else:
    test_target = env.Command('test.log', sdist_gen, 'touch $TARGET')

env.Alias('flaky-test', test_target)
env.Alias('controller/src/config/contrail_issu:flaky-test', test_target)
env.Alias('controller/src/config/contrail_issu/contrail_issu:flaky-test', test_target)

env.Alias('install', env.InstallAs(env['INSTALL_INITD'] +
    '/contrail-issu-run-sync', 'contrail-issu-run-sync.initd.supervisord'))
env.Alias('install', env.Install(env['INSTALL_CONF'],
    'supervisord_issu.conf'))
env.Alias('install', env.Install(env['INSTALL_CONF']+
    '/supervisord_issu_files', 'contrail-issu-run-sync.ini'))
env.Alias('install', env.InstallAs( env['INSTALL_SYSTEMD'] +
    '/contrail-issu-run-sync.service', 'systemd/contrail-issu-run-sync.service'))

# Local Variables:
# mode: python
# End:
